#include "math_utils.h"


Point3f::Point3f(float x, float y, float z)
    :x(x), y(y),z(z)
{
    coord[0] = x;
    coord[1] = y;
    coord[2] = z;
}

Point3f Point3f::operator+(const Point3f &pt) const
{
    return Point3f(x + pt.x, y + pt.y, z + pt.z);
}

Point3f Point3f::operator-(const Point3f &pt) const
{
    return Point3f(x - pt.x, y - pt.y, z - pt.z);
}

Point3f Point3f::operator=(const Point3f &pt)
{
    x = pt.x;
    y = pt.y;
    z = pt.z;
    coord[0] = x;
    coord[1] = y;
    coord[2] = z;

    return *this;
}

float* Point3f::xyz(){
    return coord;
}

Vector3::Vector3()
{
    this->x=1;
    this->y=1;
    this->z=1;
    this->w=0;
}

Vector3::Vector3(float x, float y, float z)
{
    this->x=x;
    this->y=y;
    this->z=z;
    this->w=0;
}

Vector3 Vector3::operator+(Vector3 b)
{
    Vector3 c(this->x + b.x,this->y + b.y, this->z + b.z );
    c.w = 0;
    return c;
}

void Vector3::operator=(Vector3 b)
{
    this->x=b.x;
    this->y=b.y;
    this->z=b.z;
    this->w=0;
}

Vector3 Vector3::operator-(Vector3 b)
{
    Vector3 c(this->x - b.x,this->y - b.y, this->z - b.z );
    c.w = 0;
    return c;
}

Vector3 Vector3::operator*(float num)
{
    Vector3 c(this->x*num,this->y*num, this->z*num );
    c.w = 0;
    return c;
}

float Vector3::dot(Vector3 b)
{
    return this->x*b.x + this->y*b.y + this->z*b.z;
}

Vector3 Vector3::cross(Vector3 b)
{
    Vector3 c;
    c.x = (this->y*b.z - this->z*b.y);
    c.y = (this->z*b.x - this->x*b.z);
    c.z = (this->x*b.y - this->y*b.x);
    c.w = 0;
    return c;
}

float Vector3::getMagnitude()
{
    return sqrt(this->x*this->x + this->y*this->y + this->z*this->z);
}

void Vector3::normalize()
{
    float mag = this->getMagnitude();
    this->x = this->x/mag;
    this->y = this->y/mag;
    this->z = this->z/mag;
}
